package com.skillworld.webapp.model.roomdservice;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class RoomdConfig 
{
    private static final String CONFIG_FILE = "roomd.properties";
    
    private static RoomdConfig config;
    private Properties properties;

    
    static 
    {
        config = new RoomdConfig();
        config.properties = new Properties();
        
        try 
        {
            InputStream inputStream = 
                config.getClass().getClassLoader()  
                      .getResourceAsStream(CONFIG_FILE);
            config.properties.load(inputStream);
        } catch (FileNotFoundException e) 
        { throw new RuntimeException(e); } 
        catch (IOException e) 
        { throw new RuntimeException(e); }
    }
    
    
    private RoomdConfig()
    {

    }
    
    
    public static Roomd getRoomd(String mapName)
    {
        String host = config.properties.getProperty(mapName + ".host");
        int port = Integer.parseInt(
                    config.properties.getProperty(mapName + ".port"));
        int flashpolicyPort = Integer.parseInt(
                    config.properties.getProperty(mapName + ".flashpolicy-port"));
        
        return new Roomd(mapName, host, port, flashpolicyPort);
    }
}
